import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';

import * as constants from '../../../providers/Constants'
import { ToastService } from 'src/app/providers/toast/toast.service';
import { OrderService } from 'src/app/services/order.service';
import { NavController } from '@ionic/angular';

@Component({
  selector: 'app-logistics',
  templateUrl: './logistics.page.html',
  styleUrls: ['./logistics.page.scss'],
})
export class LogisticsPage implements OnInit {
  procOrderId: string;
  merchAddressInfo: any = [];
  isGather: boolean = false;
  commentInfo: any = {};
  msg:string='';

  constructor(private activeRoute: ActivatedRoute, private order: OrderService, private toast: ToastService, private nav: NavController) {
    this.activeRoute.queryParams.subscribe((params: Params) => {
      console.log('params',params);
      if (params.commentInfo) {
        this.commentInfo = JSON.parse(params.commentInfo);
        this.procOrderId = params.procOrderId;
        this.query();
      }
    })
  }

  ngOnInit() {

  }
  AmountOfConversion(num: number) {
    return num / 100;
  }
  query() {
    this.order.queryMerchAddress({
      procOrderId: this.procOrderId
    }).subscribe(res => {
      this.msg=JSON.stringify(res);
      if (res.retCode == '000000') {
        this.merchAddressInfo = res.jsonObject.data;
         console.log(this.merchAddressInfo );

        if (res.jsonObject.data) {
          if (this.merchAddressInfo.length != 0) {
            this.isGather = true;
          }
        }
      } else if (constants.errCode[res.retCode]) {
        if (constants.errCode[res.retCode] != '0') { this.toast.show(constants.errCode[res.retCode]); }
      } else if (res.retMsg) {
        this.toast.show(res.retMsg);
      } else {
        this.toast.show("exception service routine");
      }
    })
  }
}
